package uk.ac.cam.djjb2.mygame;

import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;

public class MessageInputStream extends DataInputStream {
	private static byte[] readMessage(DataInputStream stream) throws IOException {
		byte[] data;
		synchronized(stream) {
			int size = stream.readInt();
			data = new byte[size];
			stream.read(data);
		}
		
		return data;
	}
	public MessageInputStream(DataInputStream stream) throws IOException {
		super(new ByteArrayInputStream(readMessage(stream)));
	}
}
